import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';

import '../index.dart';

class BottomAgree extends GetView<LoginController> {
  final ValueChanged<bool> onSwitchAgree;
  final VoidCallback onUserAgree;
  final VoidCallback onPrivacyAgree;
  final VoidCallback onAuthAgree;

  const BottomAgree({
    Key? key,
    required this.onSwitchAgree,
    required this.onUserAgree,
    required this.onPrivacyAgree,
    required this.onAuthAgree,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      bottom: true,
      minimum: const EdgeInsets.only(bottom: 20),
      child: Padding(
        padding: const EdgeInsets.only(bottom: 10),
        child: Wrap(
          alignment: WrapAlignment.center,
          crossAxisAlignment: WrapCrossAlignment.center,
          children: [
            Obx(
              () => SizedBox(
                width: 30,
                height: 20,
                child: Checkbox(
                  value: controller.state.agreeChecked.value,
                  activeColor: AppColors.danger,
                  side: const BorderSide(color: AppColors.active),
                  onChanged: (bool? value) {
                    if (value != null) {
                      onSwitchAgree(value);
                    }
                  },
                ),
              ),
            ),
            GestureDetector(
              onTap: () => onSwitchAgree(!controller.state.agreeChecked.value),
              child: _buildText('请阅读并同意'.tr),
            ),
            GestureDetector(
              onTap: onUserAgree,
              child: _buildText('《${'用户协议'.tr}》', FontWeight.w600),
            ),
            GestureDetector(
              onTap: onPrivacyAgree,
              child: _buildText('《${'隐私政策'.tr}》', FontWeight.w600),
            ),
            // GestureDetector(
            //   onTap: onAuthAgree,
            //   child: _buildText('《${'联通统一认证服务条款'.tr}》', FontWeight.w600),
            // ),
          ],
        ),
      ),
    );
  }

  Widget _buildText(String text, [FontWeight? fontWeight]) {
    return Text(
      text,
      style: TextStyle(
        color: AppColors.active,
        fontSize: 12,
        fontWeight: fontWeight,
      ),
    );
  }
}
